package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Answer;
import cn.wolfcode.trip.base.domain.AnswerComment;
import cn.wolfcode.trip.base.service.IAnswerCommentService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("answers/comments")
public class AnswerCommentController {

    @Autowired
    private IAnswerCommentService commentService;

    // 获取某问题下评论
    @GetMapping("/{id}")
    public List<AnswerComment> getComments(@PathVariable Long id){
        return commentService.listAllById(id);
    }

    // 新增评论
    @PostMapping("/{id}")
    public JSONResult save(@PathVariable Long id, AnswerComment comment){
        Answer answer = new Answer();
        answer.setId(id);
        comment.setAnswer(answer);
        commentService.save(comment);
        return new JSONResult();
    }
}
